﻿@namespace Masa.Blazor.Docs.Components
@inject I18n I18n

@if (Data.Keys.Count > 1)
{
    <OutlineCard Title="Component APIs"
                 Class="mb-4">
        <MChipGroup Value="@Value"
                    ValueChanged="@(v => ValueChanged.InvokeAsync(v?.ToString()))"
                    Column
                    Mandatory
                    ActiveClass="primary primary--text">
            @foreach (var key in Data.Keys)
            {
                <MChip Value="@key" Outlined Filter>@key</MChip>
            }
        </MChipGroup>
    </OutlineCard>
}

@if (Value is not null && Data.TryGetValue(Value, out var value))
{
    <div class="d-flex mb-4">
        <AppTextField @bind-Value="_filter" Icon="mdi-magnify" Clearable Label="@I18n.T("Search")" />
    </div>

    foreach (var (name, data) in value)
    {
        <ApiSection Name="@name" Data="@data" Filter="@_filter" GithubUri="@GithubUri" />
    }
}

@code {

    [Parameter]
    [EditorRequired]
    public Dictionary<string, Dictionary<string, List<ParameterInfo>>> Data { get; set; } = null!;

    [Parameter]
    public string? Value { get; set; }

    [Parameter]
    public EventCallback<string?> ValueChanged { get; set; }

    [Parameter]
    public string? GithubUri { get; set; }

    private string? _filter;

}
